package com.luohao.work.experiment2.service.demo3;

import com.luohao.work.experiment2.service.DemoService;
import com.luohao.work.experiment2.utils.KwicList;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class Demo3ServiceImpl implements DemoService {
    @Override
    public String convert(ArrayList<String> lineTxt) {

        //创建主题
        KWICSubject kwicSubject = new KWICSubject();
        //创建观察者
        Shift shift = new Shift(lineTxt);
        Alphabetizer alphabetizer = new Alphabetizer(shift.getKwicList());

        // 将观察者加入主题
        kwicSubject.addObserver(shift);
        kwicSubject.addObserver(alphabetizer);
        // 逐步调用各个观察者
        kwicSubject.startKWIC();

        return KwicList.toString(alphabetizer.getKwicList());
    }
}
